from itsdangerous import BadData
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from meiduo_mall import settings
def generate_save_token(openid):

    serializer = Serializer(settings.SECRET_KEY, expires_in=3600)
    data = {'openid': openid}
    token = serializer.dumps(data)
    return token.decode()   #将token解码成字符串

def check_save_user_token(access_token):
    serializer = Serializer(settings.SECRET_KEY, expires_in=3600)
    try:
        data = serializer.loads(access_token) #将token转换人能辨识的成字符
    except BadData:
        return None
    else:
        pass